using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.TextCore;
using UnityEngine.UI;

public class VGUI_ClickableGroup : MonoBehaviour
{
    public UIBindTarget bindListData;
    public GameObject tempPrefab;
    public List<VGUI_ClickableItem> clickableItems;
    private VGUI_ContainerBase mainContainer;

    public Action<int> OnItemClicked;

    public IList tempListData;
    private void Start()
    {
        mainContainer = GetComponentInParent<VGUI_ContainerBase>();
        tempPrefab.SetActive(false);
        Init();
    }

    public void Init()
    {
        //bindListData.CreateBinding();
    }

    public void OnSourceDataUpdate()
    {
        //TODO:更加完善的更新机制
        //if (DataSystem.GetData<IList>(bindListData.dataName, out tempListData))
        //{
        //    for (int i = clickableItems.Count; i < tempListData.Count; i++)
        //    {
        //        var item = tempListData[i] as ListableDataBase;
        //        var go = Instantiate(tempPrefab);
        //        go.transform.SetParent(transform);
        //        go.SetActive(true);

        //        var comp = go.GetComponent<VGUI_ClickableItem>();
        //        int count = 0;
        //        int index = i;
        //        foreach (var iEValue in item)
        //        {
        //            comp.bindings[count++].Invoke(iEValue);
        //        }
        //        comp.Button.onClick.AddListener(
        //            () =>
        //            {
        //                OnItemClicked?.Invoke(index);
        //                Debug.Log($"curItemIndex:{index}");
        //            }
        //        );
        //    }
        //}

    }
}
